Skip to content

printf, seq: fix abort on large field width and precision#13460

Open
eyupcanakman wants to merge 5 commits into
uutils:mainfrom
eyupcanakman:fix/printf-large-width-precision-panic
Open

printf, seq: fix abort on large field width and precision#13460
eyupcanakman wants to merge 5 commits into
uutils:mainfrom
eyupcanakman:fix/printf-large-width-precision-panic

Conversation

@eyupcanakman

Copy link
Copy Markdown
Contributor

printf and seq abort with SIGABRT on a large field width or precision:

printf '%.70000f' 1
printf '%70000d' 1
printf '%500000s' x
seq -f '%.70000f' 1 1

Rust's formatting machinery panics once a dynamic width or precision passes u16::MAX, and the release build turns that panic into an abort. GNU produces the padded output, so these now do too.

While tracing it I found a second bug in the same path. printf '%.1000f' 1 printed 1 instead of 1. and 1000 zeros, because bigdecimal's Display stops padding past 1000 digits. The %f formatter now assembles the digits directly, which fixes both. Padding is written in fixed chunks so a wide field costs no extra memory.

#12620 uses the same chunked-padding approach for the width case. This also handles the large precision and the truncation, which #12620 and #12603 leave unfixed.

seq's own precision detection derives an unbounded value from the exponent text (seq 1e-3000000000 1e-3000000000), which this does not touch. That path is tracked in #13221.

Fixes #12708

A field width or precision above u16::MAX made Rust's formatting machinery panic, which the release build turns into a SIGABRT, so `printf '%70000d' 1` and `seq -f '%.70000f' 1 1` aborted where GNU pads the output.

The %f formatter now assembles the decimal digits directly instead of going through bigdecimal's Display, which also fixes `printf '%.1000f' 1` printing `1` rather than `1.` and 1000 zeros (Display stops padding past 1000 digits). Padding is written in fixed chunks so a wide field costs no extra memory.

Fixes uutils#12708
@codspeed-hq

codspeed-hq Bot commented Jul 19, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 5.04%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 337 untouched benchmarks
⏩ 46 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory cp_recursive_deep_tree[(120, 4)] 532.7 KB 699.2 KB -23.82%
Simulation seq_formatted 94.7 ms 80 ms +18.37%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing eyupcanakman:fix/printf-large-width-precision-panic (7e19859) with main (4be96c1)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sylvestre

Copy link
Copy Markdown
Contributor

Please fix the job issue

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/expand/bounded-memory is now being skipped but was previously passing.

unpadded and bigdecimal only appear in the new comments.
decimal_digits(bd, precision)
}

/// Render `bd` in decimal notation with exactly `precision` fractional digits.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure these long comments are valuable ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed them, kept only why each branch is there. Same in the tests.

Keep why each branch is there and drop the rest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

printf/seq still panic on large float precision and field width after #12572 integer-precision fix

2 participants